import React, { useState, useCallback } from 'react'

// 父组件，给子组件传递name和changeName方法
const Parent = () => {
  const [count, setCount] = useState(1)
  const [name, setName] = useState('fly')
  const addCount = () => {
    setCount(count + 1)
  }
  const changeName = useCallback((n) => {
    setName(n)
  }, [])
  return (
    <>
      <div onClick={addCount}>计数: {count}</div>
      <Child name={name} changeName={changeName} />
    </>
  )
}

// 子组件
const Child = ({ name, changeName }) => {
  console.log('child start---')
  return (
    <div
      onClick={() => {
        changeName('ide')
      }}
    >
      child comps: {name}
    </div>
  )
}

export default Parent
